
_kill:     file format elf32-i386


Disassembly of section .text:

00000000 <main>:
#include "stat.h"
#include "user.h"

int
main(int argc, char **argv)
{
   0:	55                   	push   %ebp
   1:	89 e5                	mov    %esp,%ebp
   3:	83 e4 f0             	and    $0xfffffff0,%esp
   6:	83 ec 20             	sub    $0x20,%esp
  int i;

  if(argc < 1){
   9:	83 7d 08 00          	cmpl   $0x0,0x8(%ebp)
   d:	7f 19                	jg     28 <main+0x28>
    printf(2, "usage: kill pid...\n");
   f:	c7 44 24 04 be 0e 00 	movl   $0xebe,0x4(%esp)
  16:	00 
  17:	c7 04 24 02 00 00 00 	movl   $0x2,(%esp)
  1e:	e8 4a 04 00 00       	call   46d <printf>
    exit();
  23:	e8 a8 02 00 00       	call   2d0 <exit>
  }
  for(i=1; i<argc; i++)
  28:	c7 44 24 1c 01 00 00 	movl   $0x1,0x1c(%esp)
  2f:	00 
  30:	eb 27                	jmp    59 <main+0x59>
    kill(atoi(argv[i]));
  32:	8b 44 24 1c          	mov    0x1c(%esp),%eax
  36:	8d 14 85 00 00 00 00 	lea    0x0(,%eax,4),%edx
  3d:	8b 45 0c             	mov    0xc(%ebp),%eax
  40:	01 d0                	add    %edx,%eax
  42:	8b 00                	mov    (%eax),%eax
  44:	89 04 24             	mov    %eax,(%esp)
  47:	e8 f5 01 00 00       	call   241 <atoi>
  4c:	89 04 24             	mov    %eax,(%esp)
  4f:	e8 ac 02 00 00       	call   300 <kill>

  if(argc < 1){
    printf(2, "usage: kill pid...\n");
    exit();
  }
  for(i=1; i<argc; i++)
  54:	83 44 24 1c 01       	addl   $0x1,0x1c(%esp)
  59:	8b 44 24 1c          	mov    0x1c(%esp),%eax
  5d:	3b 45 08             	cmp    0x8(%ebp),%eax
  60:	7c d0                	jl     32 <main+0x32>
    kill(atoi(argv[i]));
  exit();
  62:	e8 69 02 00 00       	call   2d0 <exit>
  67:	90                   	nop

00000068 <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
  68:	55                   	push   %ebp
  69:	89 e5                	mov    %esp,%ebp
  6b:	57                   	push   %edi
  6c:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
  6d:	8b 4d 08             	mov    0x8(%ebp),%ecx
  70:	8b 55 10             	mov    0x10(%ebp),%edx
  73:	8b 45 0c             	mov    0xc(%ebp),%eax
  76:	89 cb                	mov    %ecx,%ebx
  78:	89 df                	mov    %ebx,%edi
  7a:	89 d1                	mov    %edx,%ecx
  7c:	fc                   	cld    
  7d:	f3 aa                	rep stos %al,%es:(%edi)
  7f:	89 ca                	mov    %ecx,%edx
  81:	89 fb                	mov    %edi,%ebx
  83:	89 5d 08             	mov    %ebx,0x8(%ebp)
  86:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
  89:	5b                   	pop    %ebx
  8a:	5f                   	pop    %edi
  8b:	5d                   	pop    %ebp
  8c:	c3                   	ret    

0000008d <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
  8d:	55                   	push   %ebp
  8e:	89 e5                	mov    %esp,%ebp
  90:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
  93:	8b 45 08             	mov    0x8(%ebp),%eax
  96:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
  99:	90                   	nop
  9a:	8b 45 0c             	mov    0xc(%ebp),%eax
  9d:	0f b6 10             	movzbl (%eax),%edx
  a0:	8b 45 08             	mov    0x8(%ebp),%eax
  a3:	88 10                	mov    %dl,(%eax)
  a5:	8b 45 08             	mov    0x8(%ebp),%eax
  a8:	0f b6 00             	movzbl (%eax),%eax
  ab:	84 c0                	test   %al,%al
  ad:	0f 95 c0             	setne  %al
  b0:	83 45 08 01          	addl   $0x1,0x8(%ebp)
  b4:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
  b8:	84 c0                	test   %al,%al
  ba:	75 de                	jne    9a <strcpy+0xd>
    ;
  return os;
  bc:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
  bf:	c9                   	leave  
  c0:	c3                   	ret    

000000c1 <strcmp>:

int
strcmp(const char *p, const char *q)
{
  c1:	55                   	push   %ebp
  c2:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
  c4:	eb 08                	jmp    ce <strcmp+0xd>
    p++, q++;
  c6:	83 45 08 01          	addl   $0x1,0x8(%ebp)
  ca:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
  ce:	8b 45 08             	mov    0x8(%ebp),%eax
  d1:	0f b6 00             	movzbl (%eax),%eax
  d4:	84 c0                	test   %al,%al
  d6:	74 10                	je     e8 <strcmp+0x27>
  d8:	8b 45 08             	mov    0x8(%ebp),%eax
  db:	0f b6 10             	movzbl (%eax),%edx
  de:	8b 45 0c             	mov    0xc(%ebp),%eax
  e1:	0f b6 00             	movzbl (%eax),%eax
  e4:	38 c2                	cmp    %al,%dl
  e6:	74 de                	je     c6 <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
  e8:	8b 45 08             	mov    0x8(%ebp),%eax
  eb:	0f b6 00             	movzbl (%eax),%eax
  ee:	0f b6 d0             	movzbl %al,%edx
  f1:	8b 45 0c             	mov    0xc(%ebp),%eax
  f4:	0f b6 00             	movzbl (%eax),%eax
  f7:	0f b6 c0             	movzbl %al,%eax
  fa:	89 d1                	mov    %edx,%ecx
  fc:	29 c1                	sub    %eax,%ecx
  fe:	89 c8                	mov    %ecx,%eax
}
 100:	5d                   	pop    %ebp
 101:	c3                   	ret    

00000102 <strlen>:

uint
strlen(char *s)
{
 102:	55                   	push   %ebp
 103:	89 e5                	mov    %esp,%ebp
 105:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
 108:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 10f:	eb 04                	jmp    115 <strlen+0x13>
 111:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 115:	8b 55 fc             	mov    -0x4(%ebp),%edx
 118:	8b 45 08             	mov    0x8(%ebp),%eax
 11b:	01 d0                	add    %edx,%eax
 11d:	0f b6 00             	movzbl (%eax),%eax
 120:	84 c0                	test   %al,%al
 122:	75 ed                	jne    111 <strlen+0xf>
    ;
  return n;
 124:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 127:	c9                   	leave  
 128:	c3                   	ret    

00000129 <memset>:

void*
memset(void *dst, int c, uint n)
{
 129:	55                   	push   %ebp
 12a:	89 e5                	mov    %esp,%ebp
 12c:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
 12f:	8b 45 10             	mov    0x10(%ebp),%eax
 132:	89 44 24 08          	mov    %eax,0x8(%esp)
 136:	8b 45 0c             	mov    0xc(%ebp),%eax
 139:	89 44 24 04          	mov    %eax,0x4(%esp)
 13d:	8b 45 08             	mov    0x8(%ebp),%eax
 140:	89 04 24             	mov    %eax,(%esp)
 143:	e8 20 ff ff ff       	call   68 <stosb>
  return dst;
 148:	8b 45 08             	mov    0x8(%ebp),%eax
}
 14b:	c9                   	leave  
 14c:	c3                   	ret    

0000014d <strchr>:

char*
strchr(const char *s, char c)
{
 14d:	55                   	push   %ebp
 14e:	89 e5                	mov    %esp,%ebp
 150:	83 ec 04             	sub    $0x4,%esp
 153:	8b 45 0c             	mov    0xc(%ebp),%eax
 156:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
 159:	eb 14                	jmp    16f <strchr+0x22>
    if(*s == c)
 15b:	8b 45 08             	mov    0x8(%ebp),%eax
 15e:	0f b6 00             	movzbl (%eax),%eax
 161:	3a 45 fc             	cmp    -0x4(%ebp),%al
 164:	75 05                	jne    16b <strchr+0x1e>
      return (char*)s;
 166:	8b 45 08             	mov    0x8(%ebp),%eax
 169:	eb 13                	jmp    17e <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
 16b:	83 45 08 01          	addl   $0x1,0x8(%ebp)
 16f:	8b 45 08             	mov    0x8(%ebp),%eax
 172:	0f b6 00             	movzbl (%eax),%eax
 175:	84 c0                	test   %al,%al
 177:	75 e2                	jne    15b <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
 179:	b8 00 00 00 00       	mov    $0x0,%eax
}
 17e:	c9                   	leave  
 17f:	c3                   	ret    

00000180 <gets>:

char*
gets(char *buf, int max)
{
 180:	55                   	push   %ebp
 181:	89 e5                	mov    %esp,%ebp
 183:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 186:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 18d:	eb 46                	jmp    1d5 <gets+0x55>
    cc = read(0, &c, 1);
 18f:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 196:	00 
 197:	8d 45 ef             	lea    -0x11(%ebp),%eax
 19a:	89 44 24 04          	mov    %eax,0x4(%esp)
 19e:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 1a5:	e8 3e 01 00 00       	call   2e8 <read>
 1aa:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
 1ad:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 1b1:	7e 2f                	jle    1e2 <gets+0x62>
      break;
    buf[i++] = c;
 1b3:	8b 55 f4             	mov    -0xc(%ebp),%edx
 1b6:	8b 45 08             	mov    0x8(%ebp),%eax
 1b9:	01 c2                	add    %eax,%edx
 1bb:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1bf:	88 02                	mov    %al,(%edx)
 1c1:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
 1c5:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1c9:	3c 0a                	cmp    $0xa,%al
 1cb:	74 16                	je     1e3 <gets+0x63>
 1cd:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1d1:	3c 0d                	cmp    $0xd,%al
 1d3:	74 0e                	je     1e3 <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 1d5:	8b 45 f4             	mov    -0xc(%ebp),%eax
 1d8:	83 c0 01             	add    $0x1,%eax
 1db:	3b 45 0c             	cmp    0xc(%ebp),%eax
 1de:	7c af                	jl     18f <gets+0xf>
 1e0:	eb 01                	jmp    1e3 <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
 1e2:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
 1e3:	8b 55 f4             	mov    -0xc(%ebp),%edx
 1e6:	8b 45 08             	mov    0x8(%ebp),%eax
 1e9:	01 d0                	add    %edx,%eax
 1eb:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
 1ee:	8b 45 08             	mov    0x8(%ebp),%eax
}
 1f1:	c9                   	leave  
 1f2:	c3                   	ret    

000001f3 <stat>:

int
stat(char *n, struct stat *st)
{
 1f3:	55                   	push   %ebp
 1f4:	89 e5                	mov    %esp,%ebp
 1f6:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
 1f9:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
 200:	00 
 201:	8b 45 08             	mov    0x8(%ebp),%eax
 204:	89 04 24             	mov    %eax,(%esp)
 207:	e8 04 01 00 00       	call   310 <open>
 20c:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
 20f:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 213:	79 07                	jns    21c <stat+0x29>
    return -1;
 215:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
 21a:	eb 23                	jmp    23f <stat+0x4c>
  r = fstat(fd, st);
 21c:	8b 45 0c             	mov    0xc(%ebp),%eax
 21f:	89 44 24 04          	mov    %eax,0x4(%esp)
 223:	8b 45 f4             	mov    -0xc(%ebp),%eax
 226:	89 04 24             	mov    %eax,(%esp)
 229:	e8 fa 00 00 00       	call   328 <fstat>
 22e:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
 231:	8b 45 f4             	mov    -0xc(%ebp),%eax
 234:	89 04 24             	mov    %eax,(%esp)
 237:	e8 bc 00 00 00       	call   2f8 <close>
  return r;
 23c:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
 23f:	c9                   	leave  
 240:	c3                   	ret    

00000241 <atoi>:

int
atoi(const char *s)
{
 241:	55                   	push   %ebp
 242:	89 e5                	mov    %esp,%ebp
 244:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
 247:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
 24e:	eb 23                	jmp    273 <atoi+0x32>
    n = n*10 + *s++ - '0';
 250:	8b 55 fc             	mov    -0x4(%ebp),%edx
 253:	89 d0                	mov    %edx,%eax
 255:	c1 e0 02             	shl    $0x2,%eax
 258:	01 d0                	add    %edx,%eax
 25a:	01 c0                	add    %eax,%eax
 25c:	89 c2                	mov    %eax,%edx
 25e:	8b 45 08             	mov    0x8(%ebp),%eax
 261:	0f b6 00             	movzbl (%eax),%eax
 264:	0f be c0             	movsbl %al,%eax
 267:	01 d0                	add    %edx,%eax
 269:	83 e8 30             	sub    $0x30,%eax
 26c:	89 45 fc             	mov    %eax,-0x4(%ebp)
 26f:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
 273:	8b 45 08             	mov    0x8(%ebp),%eax
 276:	0f b6 00             	movzbl (%eax),%eax
 279:	3c 2f                	cmp    $0x2f,%al
 27b:	7e 0a                	jle    287 <atoi+0x46>
 27d:	8b 45 08             	mov    0x8(%ebp),%eax
 280:	0f b6 00             	movzbl (%eax),%eax
 283:	3c 39                	cmp    $0x39,%al
 285:	7e c9                	jle    250 <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
 287:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 28a:	c9                   	leave  
 28b:	c3                   	ret    

0000028c <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
 28c:	55                   	push   %ebp
 28d:	89 e5                	mov    %esp,%ebp
 28f:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
 292:	8b 45 08             	mov    0x8(%ebp),%eax
 295:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
 298:	8b 45 0c             	mov    0xc(%ebp),%eax
 29b:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
 29e:	eb 13                	jmp    2b3 <memmove+0x27>
    *dst++ = *src++;
 2a0:	8b 45 f8             	mov    -0x8(%ebp),%eax
 2a3:	0f b6 10             	movzbl (%eax),%edx
 2a6:	8b 45 fc             	mov    -0x4(%ebp),%eax
 2a9:	88 10                	mov    %dl,(%eax)
 2ab:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 2af:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
 2b3:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
 2b7:	0f 9f c0             	setg   %al
 2ba:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
 2be:	84 c0                	test   %al,%al
 2c0:	75 de                	jne    2a0 <memmove+0x14>
    *dst++ = *src++;
  return vdst;
 2c2:	8b 45 08             	mov    0x8(%ebp),%eax
}
 2c5:	c9                   	leave  
 2c6:	c3                   	ret    
 2c7:	90                   	nop

000002c8 <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
 2c8:	b8 01 00 00 00       	mov    $0x1,%eax
 2cd:	cd 40                	int    $0x40
 2cf:	c3                   	ret    

000002d0 <exit>:
SYSCALL(exit)
 2d0:	b8 02 00 00 00       	mov    $0x2,%eax
 2d5:	cd 40                	int    $0x40
 2d7:	c3                   	ret    

000002d8 <wait>:
SYSCALL(wait)
 2d8:	b8 03 00 00 00       	mov    $0x3,%eax
 2dd:	cd 40                	int    $0x40
 2df:	c3                   	ret    

000002e0 <pipe>:
SYSCALL(pipe)
 2e0:	b8 04 00 00 00       	mov    $0x4,%eax
 2e5:	cd 40                	int    $0x40
 2e7:	c3                   	ret    

000002e8 <read>:
SYSCALL(read)
 2e8:	b8 05 00 00 00       	mov    $0x5,%eax
 2ed:	cd 40                	int    $0x40
 2ef:	c3                   	ret    

000002f0 <write>:
SYSCALL(write)
 2f0:	b8 10 00 00 00       	mov    $0x10,%eax
 2f5:	cd 40                	int    $0x40
 2f7:	c3                   	ret    

000002f8 <close>:
SYSCALL(close)
 2f8:	b8 15 00 00 00       	mov    $0x15,%eax
 2fd:	cd 40                	int    $0x40
 2ff:	c3                   	ret    

00000300 <kill>:
SYSCALL(kill)
 300:	b8 06 00 00 00       	mov    $0x6,%eax
 305:	cd 40                	int    $0x40
 307:	c3                   	ret    

00000308 <exec>:
SYSCALL(exec)
 308:	b8 07 00 00 00       	mov    $0x7,%eax
 30d:	cd 40                	int    $0x40
 30f:	c3                   	ret    

00000310 <open>:
SYSCALL(open)
 310:	b8 0f 00 00 00       	mov    $0xf,%eax
 315:	cd 40                	int    $0x40
 317:	c3                   	ret    

00000318 <mknod>:
SYSCALL(mknod)
 318:	b8 11 00 00 00       	mov    $0x11,%eax
 31d:	cd 40                	int    $0x40
 31f:	c3                   	ret    

00000320 <unlink>:
SYSCALL(unlink)
 320:	b8 12 00 00 00       	mov    $0x12,%eax
 325:	cd 40                	int    $0x40
 327:	c3                   	ret    

00000328 <fstat>:
SYSCALL(fstat)
 328:	b8 08 00 00 00       	mov    $0x8,%eax
 32d:	cd 40                	int    $0x40
 32f:	c3                   	ret    

00000330 <link>:
SYSCALL(link)
 330:	b8 13 00 00 00       	mov    $0x13,%eax
 335:	cd 40                	int    $0x40
 337:	c3                   	ret    

00000338 <mkdir>:
SYSCALL(mkdir)
 338:	b8 14 00 00 00       	mov    $0x14,%eax
 33d:	cd 40                	int    $0x40
 33f:	c3                   	ret    

00000340 <chdir>:
SYSCALL(chdir)
 340:	b8 09 00 00 00       	mov    $0x9,%eax
 345:	cd 40                	int    $0x40
 347:	c3                   	ret    

00000348 <dup>:
SYSCALL(dup)
 348:	b8 0a 00 00 00       	mov    $0xa,%eax
 34d:	cd 40                	int    $0x40
 34f:	c3                   	ret    

00000350 <getpid>:
SYSCALL(getpid)
 350:	b8 0b 00 00 00       	mov    $0xb,%eax
 355:	cd 40                	int    $0x40
 357:	c3                   	ret    

00000358 <sbrk>:
SYSCALL(sbrk)
 358:	b8 0c 00 00 00       	mov    $0xc,%eax
 35d:	cd 40                	int    $0x40
 35f:	c3                   	ret    

00000360 <sleep>:
SYSCALL(sleep)
 360:	b8 0d 00 00 00       	mov    $0xd,%eax
 365:	cd 40                	int    $0x40
 367:	c3                   	ret    

00000368 <uptime>:
SYSCALL(uptime)
 368:	b8 0e 00 00 00       	mov    $0xe,%eax
 36d:	cd 40                	int    $0x40
 36f:	c3                   	ret    

00000370 <signal>:

//our addition
SYSCALL(signal)
 370:	b8 1f 00 00 00       	mov    $0x1f,%eax
 375:	cd 40                	int    $0x40
 377:	c3                   	ret    

00000378 <sigsend>:
SYSCALL(sigsend)
 378:	b8 20 00 00 00       	mov    $0x20,%eax
 37d:	cd 40                	int    $0x40
 37f:	c3                   	ret    

00000380 <alarm>:
SYSCALL(alarm)
 380:	b8 21 00 00 00       	mov    $0x21,%eax
 385:	cd 40                	int    $0x40
 387:	c3                   	ret    

00000388 <getTicks>:
SYSCALL(getTicks)
 388:	b8 22 00 00 00       	mov    $0x22,%eax
 38d:	cd 40                	int    $0x40
 38f:	c3                   	ret    

00000390 <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
 390:	55                   	push   %ebp
 391:	89 e5                	mov    %esp,%ebp
 393:	83 ec 28             	sub    $0x28,%esp
 396:	8b 45 0c             	mov    0xc(%ebp),%eax
 399:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
 39c:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 3a3:	00 
 3a4:	8d 45 f4             	lea    -0xc(%ebp),%eax
 3a7:	89 44 24 04          	mov    %eax,0x4(%esp)
 3ab:	8b 45 08             	mov    0x8(%ebp),%eax
 3ae:	89 04 24             	mov    %eax,(%esp)
 3b1:	e8 3a ff ff ff       	call   2f0 <write>
}
 3b6:	c9                   	leave  
 3b7:	c3                   	ret    

000003b8 <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
 3b8:	55                   	push   %ebp
 3b9:	89 e5                	mov    %esp,%ebp
 3bb:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
 3be:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
 3c5:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
 3c9:	74 17                	je     3e2 <printint+0x2a>
 3cb:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 3cf:	79 11                	jns    3e2 <printint+0x2a>
    neg = 1;
 3d1:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
 3d8:	8b 45 0c             	mov    0xc(%ebp),%eax
 3db:	f7 d8                	neg    %eax
 3dd:	89 45 ec             	mov    %eax,-0x14(%ebp)
 3e0:	eb 06                	jmp    3e8 <printint+0x30>
  } else {
    x = xx;
 3e2:	8b 45 0c             	mov    0xc(%ebp),%eax
 3e5:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
 3e8:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
 3ef:	8b 4d 10             	mov    0x10(%ebp),%ecx
 3f2:	8b 45 ec             	mov    -0x14(%ebp),%eax
 3f5:	ba 00 00 00 00       	mov    $0x0,%edx
 3fa:	f7 f1                	div    %ecx
 3fc:	89 d0                	mov    %edx,%eax
 3fe:	0f b6 80 30 13 00 00 	movzbl 0x1330(%eax),%eax
 405:	8d 4d dc             	lea    -0x24(%ebp),%ecx
 408:	8b 55 f4             	mov    -0xc(%ebp),%edx
 40b:	01 ca                	add    %ecx,%edx
 40d:	88 02                	mov    %al,(%edx)
 40f:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
 413:	8b 55 10             	mov    0x10(%ebp),%edx
 416:	89 55 d4             	mov    %edx,-0x2c(%ebp)
 419:	8b 45 ec             	mov    -0x14(%ebp),%eax
 41c:	ba 00 00 00 00       	mov    $0x0,%edx
 421:	f7 75 d4             	divl   -0x2c(%ebp)
 424:	89 45 ec             	mov    %eax,-0x14(%ebp)
 427:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 42b:	75 c2                	jne    3ef <printint+0x37>
  if(neg)
 42d:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 431:	74 2e                	je     461 <printint+0xa9>
    buf[i++] = '-';
 433:	8d 55 dc             	lea    -0x24(%ebp),%edx
 436:	8b 45 f4             	mov    -0xc(%ebp),%eax
 439:	01 d0                	add    %edx,%eax
 43b:	c6 00 2d             	movb   $0x2d,(%eax)
 43e:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
 442:	eb 1d                	jmp    461 <printint+0xa9>
    putc(fd, buf[i]);
 444:	8d 55 dc             	lea    -0x24(%ebp),%edx
 447:	8b 45 f4             	mov    -0xc(%ebp),%eax
 44a:	01 d0                	add    %edx,%eax
 44c:	0f b6 00             	movzbl (%eax),%eax
 44f:	0f be c0             	movsbl %al,%eax
 452:	89 44 24 04          	mov    %eax,0x4(%esp)
 456:	8b 45 08             	mov    0x8(%ebp),%eax
 459:	89 04 24             	mov    %eax,(%esp)
 45c:	e8 2f ff ff ff       	call   390 <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
 461:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
 465:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 469:	79 d9                	jns    444 <printint+0x8c>
    putc(fd, buf[i]);
}
 46b:	c9                   	leave  
 46c:	c3                   	ret    

0000046d <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
 46d:	55                   	push   %ebp
 46e:	89 e5                	mov    %esp,%ebp
 470:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
 473:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
 47a:	8d 45 0c             	lea    0xc(%ebp),%eax
 47d:	83 c0 04             	add    $0x4,%eax
 480:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
 483:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
 48a:	e9 7d 01 00 00       	jmp    60c <printf+0x19f>
    c = fmt[i] & 0xff;
 48f:	8b 55 0c             	mov    0xc(%ebp),%edx
 492:	8b 45 f0             	mov    -0x10(%ebp),%eax
 495:	01 d0                	add    %edx,%eax
 497:	0f b6 00             	movzbl (%eax),%eax
 49a:	0f be c0             	movsbl %al,%eax
 49d:	25 ff 00 00 00       	and    $0xff,%eax
 4a2:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
 4a5:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 4a9:	75 2c                	jne    4d7 <printf+0x6a>
      if(c == '%'){
 4ab:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 4af:	75 0c                	jne    4bd <printf+0x50>
        state = '%';
 4b1:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
 4b8:	e9 4b 01 00 00       	jmp    608 <printf+0x19b>
      } else {
        putc(fd, c);
 4bd:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 4c0:	0f be c0             	movsbl %al,%eax
 4c3:	89 44 24 04          	mov    %eax,0x4(%esp)
 4c7:	8b 45 08             	mov    0x8(%ebp),%eax
 4ca:	89 04 24             	mov    %eax,(%esp)
 4cd:	e8 be fe ff ff       	call   390 <putc>
 4d2:	e9 31 01 00 00       	jmp    608 <printf+0x19b>
      }
    } else if(state == '%'){
 4d7:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
 4db:	0f 85 27 01 00 00    	jne    608 <printf+0x19b>
      if(c == 'd'){
 4e1:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
 4e5:	75 2d                	jne    514 <printf+0xa7>
        printint(fd, *ap, 10, 1);
 4e7:	8b 45 e8             	mov    -0x18(%ebp),%eax
 4ea:	8b 00                	mov    (%eax),%eax
 4ec:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
 4f3:	00 
 4f4:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
 4fb:	00 
 4fc:	89 44 24 04          	mov    %eax,0x4(%esp)
 500:	8b 45 08             	mov    0x8(%ebp),%eax
 503:	89 04 24             	mov    %eax,(%esp)
 506:	e8 ad fe ff ff       	call   3b8 <printint>
        ap++;
 50b:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 50f:	e9 ed 00 00 00       	jmp    601 <printf+0x194>
      } else if(c == 'x' || c == 'p'){
 514:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
 518:	74 06                	je     520 <printf+0xb3>
 51a:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
 51e:	75 2d                	jne    54d <printf+0xe0>
        printint(fd, *ap, 16, 0);
 520:	8b 45 e8             	mov    -0x18(%ebp),%eax
 523:	8b 00                	mov    (%eax),%eax
 525:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
 52c:	00 
 52d:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
 534:	00 
 535:	89 44 24 04          	mov    %eax,0x4(%esp)
 539:	8b 45 08             	mov    0x8(%ebp),%eax
 53c:	89 04 24             	mov    %eax,(%esp)
 53f:	e8 74 fe ff ff       	call   3b8 <printint>
        ap++;
 544:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 548:	e9 b4 00 00 00       	jmp    601 <printf+0x194>
      } else if(c == 's'){
 54d:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
 551:	75 46                	jne    599 <printf+0x12c>
        s = (char*)*ap;
 553:	8b 45 e8             	mov    -0x18(%ebp),%eax
 556:	8b 00                	mov    (%eax),%eax
 558:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
 55b:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
 55f:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 563:	75 27                	jne    58c <printf+0x11f>
          s = "(null)";
 565:	c7 45 f4 d2 0e 00 00 	movl   $0xed2,-0xc(%ebp)
        while(*s != 0){
 56c:	eb 1e                	jmp    58c <printf+0x11f>
          putc(fd, *s);
 56e:	8b 45 f4             	mov    -0xc(%ebp),%eax
 571:	0f b6 00             	movzbl (%eax),%eax
 574:	0f be c0             	movsbl %al,%eax
 577:	89 44 24 04          	mov    %eax,0x4(%esp)
 57b:	8b 45 08             	mov    0x8(%ebp),%eax
 57e:	89 04 24             	mov    %eax,(%esp)
 581:	e8 0a fe ff ff       	call   390 <putc>
          s++;
 586:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 58a:	eb 01                	jmp    58d <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
 58c:	90                   	nop
 58d:	8b 45 f4             	mov    -0xc(%ebp),%eax
 590:	0f b6 00             	movzbl (%eax),%eax
 593:	84 c0                	test   %al,%al
 595:	75 d7                	jne    56e <printf+0x101>
 597:	eb 68                	jmp    601 <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
 599:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
 59d:	75 1d                	jne    5bc <printf+0x14f>
        putc(fd, *ap);
 59f:	8b 45 e8             	mov    -0x18(%ebp),%eax
 5a2:	8b 00                	mov    (%eax),%eax
 5a4:	0f be c0             	movsbl %al,%eax
 5a7:	89 44 24 04          	mov    %eax,0x4(%esp)
 5ab:	8b 45 08             	mov    0x8(%ebp),%eax
 5ae:	89 04 24             	mov    %eax,(%esp)
 5b1:	e8 da fd ff ff       	call   390 <putc>
        ap++;
 5b6:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 5ba:	eb 45                	jmp    601 <printf+0x194>
      } else if(c == '%'){
 5bc:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 5c0:	75 17                	jne    5d9 <printf+0x16c>
        putc(fd, c);
 5c2:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 5c5:	0f be c0             	movsbl %al,%eax
 5c8:	89 44 24 04          	mov    %eax,0x4(%esp)
 5cc:	8b 45 08             	mov    0x8(%ebp),%eax
 5cf:	89 04 24             	mov    %eax,(%esp)
 5d2:	e8 b9 fd ff ff       	call   390 <putc>
 5d7:	eb 28                	jmp    601 <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
 5d9:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
 5e0:	00 
 5e1:	8b 45 08             	mov    0x8(%ebp),%eax
 5e4:	89 04 24             	mov    %eax,(%esp)
 5e7:	e8 a4 fd ff ff       	call   390 <putc>
        putc(fd, c);
 5ec:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 5ef:	0f be c0             	movsbl %al,%eax
 5f2:	89 44 24 04          	mov    %eax,0x4(%esp)
 5f6:	8b 45 08             	mov    0x8(%ebp),%eax
 5f9:	89 04 24             	mov    %eax,(%esp)
 5fc:	e8 8f fd ff ff       	call   390 <putc>
      }
      state = 0;
 601:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
 608:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
 60c:	8b 55 0c             	mov    0xc(%ebp),%edx
 60f:	8b 45 f0             	mov    -0x10(%ebp),%eax
 612:	01 d0                	add    %edx,%eax
 614:	0f b6 00             	movzbl (%eax),%eax
 617:	84 c0                	test   %al,%al
 619:	0f 85 70 fe ff ff    	jne    48f <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
 61f:	c9                   	leave  
 620:	c3                   	ret    
 621:	66 90                	xchg   %ax,%ax
 623:	90                   	nop

00000624 <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
 624:	55                   	push   %ebp
 625:	89 e5                	mov    %esp,%ebp
 627:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
 62a:	8b 45 08             	mov    0x8(%ebp),%eax
 62d:	83 e8 08             	sub    $0x8,%eax
 630:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 633:	a1 68 13 00 00       	mov    0x1368,%eax
 638:	89 45 fc             	mov    %eax,-0x4(%ebp)
 63b:	eb 24                	jmp    661 <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
 63d:	8b 45 fc             	mov    -0x4(%ebp),%eax
 640:	8b 00                	mov    (%eax),%eax
 642:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 645:	77 12                	ja     659 <free+0x35>
 647:	8b 45 f8             	mov    -0x8(%ebp),%eax
 64a:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 64d:	77 24                	ja     673 <free+0x4f>
 64f:	8b 45 fc             	mov    -0x4(%ebp),%eax
 652:	8b 00                	mov    (%eax),%eax
 654:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 657:	77 1a                	ja     673 <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 659:	8b 45 fc             	mov    -0x4(%ebp),%eax
 65c:	8b 00                	mov    (%eax),%eax
 65e:	89 45 fc             	mov    %eax,-0x4(%ebp)
 661:	8b 45 f8             	mov    -0x8(%ebp),%eax
 664:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 667:	76 d4                	jbe    63d <free+0x19>
 669:	8b 45 fc             	mov    -0x4(%ebp),%eax
 66c:	8b 00                	mov    (%eax),%eax
 66e:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 671:	76 ca                	jbe    63d <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
 673:	8b 45 f8             	mov    -0x8(%ebp),%eax
 676:	8b 40 04             	mov    0x4(%eax),%eax
 679:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 680:	8b 45 f8             	mov    -0x8(%ebp),%eax
 683:	01 c2                	add    %eax,%edx
 685:	8b 45 fc             	mov    -0x4(%ebp),%eax
 688:	8b 00                	mov    (%eax),%eax
 68a:	39 c2                	cmp    %eax,%edx
 68c:	75 24                	jne    6b2 <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
 68e:	8b 45 f8             	mov    -0x8(%ebp),%eax
 691:	8b 50 04             	mov    0x4(%eax),%edx
 694:	8b 45 fc             	mov    -0x4(%ebp),%eax
 697:	8b 00                	mov    (%eax),%eax
 699:	8b 40 04             	mov    0x4(%eax),%eax
 69c:	01 c2                	add    %eax,%edx
 69e:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6a1:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
 6a4:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6a7:	8b 00                	mov    (%eax),%eax
 6a9:	8b 10                	mov    (%eax),%edx
 6ab:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6ae:	89 10                	mov    %edx,(%eax)
 6b0:	eb 0a                	jmp    6bc <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
 6b2:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6b5:	8b 10                	mov    (%eax),%edx
 6b7:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6ba:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
 6bc:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6bf:	8b 40 04             	mov    0x4(%eax),%eax
 6c2:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 6c9:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6cc:	01 d0                	add    %edx,%eax
 6ce:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 6d1:	75 20                	jne    6f3 <free+0xcf>
    p->s.size += bp->s.size;
 6d3:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6d6:	8b 50 04             	mov    0x4(%eax),%edx
 6d9:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6dc:	8b 40 04             	mov    0x4(%eax),%eax
 6df:	01 c2                	add    %eax,%edx
 6e1:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6e4:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
 6e7:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6ea:	8b 10                	mov    (%eax),%edx
 6ec:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6ef:	89 10                	mov    %edx,(%eax)
 6f1:	eb 08                	jmp    6fb <free+0xd7>
  } else
    p->s.ptr = bp;
 6f3:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6f6:	8b 55 f8             	mov    -0x8(%ebp),%edx
 6f9:	89 10                	mov    %edx,(%eax)
  freep = p;
 6fb:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6fe:	a3 68 13 00 00       	mov    %eax,0x1368
}
 703:	c9                   	leave  
 704:	c3                   	ret    

00000705 <morecore>:

static Header*
morecore(uint nu)
{
 705:	55                   	push   %ebp
 706:	89 e5                	mov    %esp,%ebp
 708:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
 70b:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
 712:	77 07                	ja     71b <morecore+0x16>
    nu = 4096;
 714:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
 71b:	8b 45 08             	mov    0x8(%ebp),%eax
 71e:	c1 e0 03             	shl    $0x3,%eax
 721:	89 04 24             	mov    %eax,(%esp)
 724:	e8 2f fc ff ff       	call   358 <sbrk>
 729:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
 72c:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
 730:	75 07                	jne    739 <morecore+0x34>
    return 0;
 732:	b8 00 00 00 00       	mov    $0x0,%eax
 737:	eb 22                	jmp    75b <morecore+0x56>
  hp = (Header*)p;
 739:	8b 45 f4             	mov    -0xc(%ebp),%eax
 73c:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
 73f:	8b 45 f0             	mov    -0x10(%ebp),%eax
 742:	8b 55 08             	mov    0x8(%ebp),%edx
 745:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
 748:	8b 45 f0             	mov    -0x10(%ebp),%eax
 74b:	83 c0 08             	add    $0x8,%eax
 74e:	89 04 24             	mov    %eax,(%esp)
 751:	e8 ce fe ff ff       	call   624 <free>
  return freep;
 756:	a1 68 13 00 00       	mov    0x1368,%eax
}
 75b:	c9                   	leave  
 75c:	c3                   	ret    

0000075d <malloc>:

void*
malloc(uint nbytes)
{
 75d:	55                   	push   %ebp
 75e:	89 e5                	mov    %esp,%ebp
 760:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
 763:	8b 45 08             	mov    0x8(%ebp),%eax
 766:	83 c0 07             	add    $0x7,%eax
 769:	c1 e8 03             	shr    $0x3,%eax
 76c:	83 c0 01             	add    $0x1,%eax
 76f:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
 772:	a1 68 13 00 00       	mov    0x1368,%eax
 777:	89 45 f0             	mov    %eax,-0x10(%ebp)
 77a:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 77e:	75 23                	jne    7a3 <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
 780:	c7 45 f0 60 13 00 00 	movl   $0x1360,-0x10(%ebp)
 787:	8b 45 f0             	mov    -0x10(%ebp),%eax
 78a:	a3 68 13 00 00       	mov    %eax,0x1368
 78f:	a1 68 13 00 00       	mov    0x1368,%eax
 794:	a3 60 13 00 00       	mov    %eax,0x1360
    base.s.size = 0;
 799:	c7 05 64 13 00 00 00 	movl   $0x0,0x1364
 7a0:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 7a3:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7a6:	8b 00                	mov    (%eax),%eax
 7a8:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
 7ab:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7ae:	8b 40 04             	mov    0x4(%eax),%eax
 7b1:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 7b4:	72 4d                	jb     803 <malloc+0xa6>
      if(p->s.size == nunits)
 7b6:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7b9:	8b 40 04             	mov    0x4(%eax),%eax
 7bc:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 7bf:	75 0c                	jne    7cd <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
 7c1:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7c4:	8b 10                	mov    (%eax),%edx
 7c6:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7c9:	89 10                	mov    %edx,(%eax)
 7cb:	eb 26                	jmp    7f3 <malloc+0x96>
      else {
        p->s.size -= nunits;
 7cd:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7d0:	8b 40 04             	mov    0x4(%eax),%eax
 7d3:	89 c2                	mov    %eax,%edx
 7d5:	2b 55 ec             	sub    -0x14(%ebp),%edx
 7d8:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7db:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
 7de:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7e1:	8b 40 04             	mov    0x4(%eax),%eax
 7e4:	c1 e0 03             	shl    $0x3,%eax
 7e7:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
 7ea:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7ed:	8b 55 ec             	mov    -0x14(%ebp),%edx
 7f0:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
 7f3:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7f6:	a3 68 13 00 00       	mov    %eax,0x1368
      return (void*)(p + 1);
 7fb:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7fe:	83 c0 08             	add    $0x8,%eax
 801:	eb 38                	jmp    83b <malloc+0xde>
    }
    if(p == freep)
 803:	a1 68 13 00 00       	mov    0x1368,%eax
 808:	39 45 f4             	cmp    %eax,-0xc(%ebp)
 80b:	75 1b                	jne    828 <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
 80d:	8b 45 ec             	mov    -0x14(%ebp),%eax
 810:	89 04 24             	mov    %eax,(%esp)
 813:	e8 ed fe ff ff       	call   705 <morecore>
 818:	89 45 f4             	mov    %eax,-0xc(%ebp)
 81b:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 81f:	75 07                	jne    828 <malloc+0xcb>
        return 0;
 821:	b8 00 00 00 00       	mov    $0x0,%eax
 826:	eb 13                	jmp    83b <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 828:	8b 45 f4             	mov    -0xc(%ebp),%eax
 82b:	89 45 f0             	mov    %eax,-0x10(%ebp)
 82e:	8b 45 f4             	mov    -0xc(%ebp),%eax
 831:	8b 00                	mov    (%eax),%eax
 833:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
 836:	e9 70 ff ff ff       	jmp    7ab <malloc+0x4e>
}
 83b:	c9                   	leave  
 83c:	c3                   	ret    
 83d:	66 90                	xchg   %ax,%ax
 83f:	90                   	nop

00000840 <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
 840:	55                   	push   %ebp
 841:	89 e5                	mov    %esp,%ebp
 843:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
 846:	c7 05 80 13 00 00 00 	movl   $0x0,0x1380
 84d:	00 00 00 
	STORE_ESP(ttable[0].esp);
 850:	89 e0                	mov    %esp,%eax
 852:	a3 84 13 00 00       	mov    %eax,0x1384
	STORE_EBP(ttable[0].ebp);
 857:	89 e8                	mov    %ebp,%eax
 859:	a3 88 13 00 00       	mov    %eax,0x1388
	ttable[0].state = T_RUNNING;
 85e:	c7 05 90 13 00 00 01 	movl   $0x1,0x1390
 865:	00 00 00 
	ttable[0].wait_num = 0;
 868:	c7 05 94 14 00 00 00 	movl   $0x0,0x1494
 86f:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 872:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 879:	eb 2c                	jmp    8a7 <uthread_init+0x67>
	{
		ttable[i].tid = i;
 87b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 87e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 884:	8d 90 80 13 00 00    	lea    0x1380(%eax),%edx
 88a:	8b 45 f4             	mov    -0xc(%ebp),%eax
 88d:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
 88f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 892:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 898:	05 90 13 00 00       	add    $0x1390,%eax
 89d:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 8a3:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 8a7:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 8ab:	7e ce                	jle    87b <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
 8ad:	c7 44 24 04 33 0b 00 	movl   $0xb33,0x4(%esp)
 8b4:	00 
 8b5:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
 8bc:	e8 af fa ff ff       	call   370 <signal>
	alarm(THREAD_QUANTA);
 8c1:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 8c8:	e8 b3 fa ff ff       	call   380 <alarm>
}
 8cd:	c9                   	leave  
 8ce:	c3                   	ret    

000008cf <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
 8cf:	55                   	push   %ebp
 8d0:	89 e5                	mov    %esp,%ebp
 8d2:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
 8d5:	60                   	pusha  
	ticks = getTicks();
 8d6:	e8 ad fa ff ff       	call   388 <getTicks>
 8db:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
 8de:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 8e5:	e8 96 fa ff ff       	call   380 <alarm>
	asm("popa");
 8ea:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
 8eb:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 8f2:	e9 02 01 00 00       	jmp    9f9 <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
 8f7:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8fa:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 900:	05 90 13 00 00       	add    $0x1390,%eax
 905:	8b 00                	mov    (%eax),%eax
 907:	85 c0                	test   %eax,%eax
 909:	0f 85 e6 00 00 00    	jne    9f5 <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
 90f:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
 916:	e8 42 fe ff ff       	call   75d <malloc>
 91b:	8b 55 f4             	mov    -0xc(%ebp),%edx
 91e:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 924:	81 c2 80 13 00 00    	add    $0x1380,%edx
 92a:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
 92d:	8b 45 f4             	mov    -0xc(%ebp),%eax
 930:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 936:	05 80 13 00 00       	add    $0x1380,%eax
 93b:	8b 40 0c             	mov    0xc(%eax),%eax
 93e:	05 00 10 00 00       	add    $0x1000,%eax
 943:	89 c4                	mov    %eax,%esp
			PUSH(arg);
 945:	8b 45 0c             	mov    0xc(%ebp),%eax
 948:	89 c7                	mov    %eax,%edi
 94a:	57                   	push   %edi
			PUSH(uthread_exit);
 94b:	b8 b9 0b 00 00       	mov    $0xbb9,%eax
 950:	89 c7                	mov    %eax,%edi
 952:	57                   	push   %edi
			PUSH(start_func);
 953:	8b 45 08             	mov    0x8(%ebp),%eax
 956:	89 c7                	mov    %eax,%edi
 958:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
 959:	b8 00 00 00 00       	mov    $0x0,%eax
 95e:	89 c7                	mov    %eax,%edi
 960:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
 961:	89 e0                	mov    %esp,%eax
 963:	8b 55 f4             	mov    -0xc(%ebp),%edx
 966:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 96c:	81 c2 80 13 00 00    	add    $0x1380,%edx
 972:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
 975:	8b 45 f4             	mov    -0xc(%ebp),%eax
 978:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 97e:	05 80 13 00 00       	add    $0x1380,%eax
 983:	8b 40 08             	mov    0x8(%eax),%eax
 986:	8b 55 f4             	mov    -0xc(%ebp),%edx
 989:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 98f:	81 c2 80 13 00 00    	add    $0x1380,%edx
 995:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
 998:	a1 6c 13 00 00       	mov    0x136c,%eax
 99d:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9a3:	05 80 13 00 00       	add    $0x1380,%eax
 9a8:	8b 40 04             	mov    0x4(%eax),%eax
 9ab:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
 9ad:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9b0:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9b6:	05 90 13 00 00       	add    $0x1390,%eax
 9bb:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
 9c1:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9c4:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9ca:	05 90 14 00 00       	add    $0x1490,%eax
 9cf:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
 9d6:	60                   	pusha  
			alarm(ticks);
 9d7:	8b 45 f0             	mov    -0x10(%ebp),%eax
 9da:	89 04 24             	mov    %eax,(%esp)
 9dd:	e8 9e f9 ff ff       	call   380 <alarm>
			asm("popa");
 9e2:	61                   	popa   
			return ttable[i].tid;
 9e3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9e6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9ec:	05 80 13 00 00       	add    $0x1380,%eax
 9f1:	8b 00                	mov    (%eax),%eax
 9f3:	eb 1e                	jmp    a13 <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
 9f5:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 9f9:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 9fd:	0f 8e f4 fe ff ff    	jle    8f7 <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
 a03:	8b 45 f0             	mov    -0x10(%ebp),%eax
 a06:	89 04 24             	mov    %eax,(%esp)
 a09:	e8 72 f9 ff ff       	call   380 <alarm>
	//failed - no free thread to use
	return -1;
 a0e:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 a13:	c9                   	leave  
 a14:	c3                   	ret    

00000a15 <safe_exit>:

// task 2.4


void safe_exit()
{
 a15:	55                   	push   %ebp
 a16:	89 e5                	mov    %esp,%ebp
 a18:	83 ec 28             	sub    $0x28,%esp
 a1b:	eb 01                	jmp    a1e <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
 a1d:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 a1e:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 a25:	eb 25                	jmp    a4c <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
 a27:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a2a:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a30:	05 90 13 00 00       	add    $0x1390,%eax
 a35:	8b 00                	mov    (%eax),%eax
 a37:	85 c0                	test   %eax,%eax
 a39:	74 0d                	je     a48 <safe_exit+0x33>
				uthread_join(tid);
 a3b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a3e:	89 04 24             	mov    %eax,(%esp)
 a41:	e8 1d 02 00 00       	call   c63 <uthread_join>
				break;
 a46:	eb 0a                	jmp    a52 <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 a48:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 a4c:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 a50:	7e d5                	jle    a27 <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
 a52:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
 a56:	75 c5                	jne    a1d <safe_exit+0x8>
			exit();
 a58:	e8 73 f8 ff ff       	call   2d0 <exit>

00000a5d <uthread_switch>:
		}
	}
}

void uthread_switch()
{
 a5d:	55                   	push   %ebp
 a5e:	89 e5                	mov    %esp,%ebp
 a60:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
 a63:	a1 6c 13 00 00       	mov    0x136c,%eax
 a68:	8d 50 01             	lea    0x1(%eax),%edx
 a6b:	89 d0                	mov    %edx,%eax
 a6d:	c1 f8 1f             	sar    $0x1f,%eax
 a70:	c1 e8 1a             	shr    $0x1a,%eax
 a73:	01 c2                	add    %eax,%edx
 a75:	83 e2 3f             	and    $0x3f,%edx
 a78:	89 d1                	mov    %edx,%ecx
 a7a:	29 c1                	sub    %eax,%ecx
 a7c:	89 c8                	mov    %ecx,%eax
 a7e:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 a81:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 a88:	eb 20                	jmp    aaa <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
 a8a:	8b 45 f0             	mov    -0x10(%ebp),%eax
 a8d:	8d 50 01             	lea    0x1(%eax),%edx
 a90:	89 d0                	mov    %edx,%eax
 a92:	c1 f8 1f             	sar    $0x1f,%eax
 a95:	c1 e8 1a             	shr    $0x1a,%eax
 a98:	01 c2                	add    %eax,%edx
 a9a:	83 e2 3f             	and    $0x3f,%edx
 a9d:	89 d1                	mov    %edx,%ecx
 a9f:	29 c1                	sub    %eax,%ecx
 aa1:	89 c8                	mov    %ecx,%eax
 aa3:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 aa6:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 aaa:	8b 45 f0             	mov    -0x10(%ebp),%eax
 aad:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 ab3:	05 90 13 00 00       	add    $0x1390,%eax
 ab8:	8b 00                	mov    (%eax),%eax
 aba:	83 f8 02             	cmp    $0x2,%eax
 abd:	74 06                	je     ac5 <uthread_switch+0x68>
 abf:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 ac3:	7e c5                	jle    a8a <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
 ac5:	8b 15 6c 13 00 00    	mov    0x136c,%edx
 acb:	89 e0                	mov    %esp,%eax
 acd:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 ad3:	81 c2 80 13 00 00    	add    $0x1380,%edx
 ad9:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
 adc:	8b 15 6c 13 00 00    	mov    0x136c,%edx
 ae2:	89 e8                	mov    %ebp,%eax
 ae4:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 aea:	81 c2 80 13 00 00    	add    $0x1380,%edx
 af0:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
 af3:	8b 45 f0             	mov    -0x10(%ebp),%eax
 af6:	a3 6c 13 00 00       	mov    %eax,0x136c
	LOAD_EBP(ttable[c_thread].ebp);
 afb:	a1 6c 13 00 00       	mov    0x136c,%eax
 b00:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b06:	05 80 13 00 00       	add    $0x1380,%eax
 b0b:	8b 40 08             	mov    0x8(%eax),%eax
 b0e:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
 b10:	a1 6c 13 00 00       	mov    0x136c,%eax
 b15:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b1b:	05 80 13 00 00       	add    $0x1380,%eax
 b20:	8b 40 04             	mov    0x4(%eax),%eax
 b23:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
 b25:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 b2c:	e8 4f f8 ff ff       	call   380 <alarm>
}
 b31:	c9                   	leave  
 b32:	c3                   	ret    

00000b33 <uthread_yield>:

void uthread_yield()
{
 b33:	55                   	push   %ebp
 b34:	89 e5                	mov    %esp,%ebp
 b36:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
 b39:	60                   	pusha  
	alarm(0);
 b3a:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 b41:	e8 3a f8 ff ff       	call   380 <alarm>
	ttable[c_thread].state = T_RUNNABLE;
 b46:	a1 6c 13 00 00       	mov    0x136c,%eax
 b4b:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b51:	05 90 13 00 00       	add    $0x1390,%eax
 b56:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
 b5c:	e8 fc fe ff ff       	call   a5d <uthread_switch>
	asm("popa");
 b61:	61                   	popa   
}
 b62:	c9                   	leave  
 b63:	c3                   	ret    

00000b64 <uthread_awake>:

// task 2.5

void uthread_awake()
{
 b64:	55                   	push   %ebp
 b65:	89 e5                	mov    %esp,%ebp
 b67:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 b6a:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 b71:	eb 2c                	jmp    b9f <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
 b73:	a1 6c 13 00 00       	mov    0x136c,%eax
 b78:	6b d0 46             	imul   $0x46,%eax,%edx
 b7b:	8b 45 fc             	mov    -0x4(%ebp),%eax
 b7e:	01 d0                	add    %edx,%eax
 b80:	83 c0 04             	add    $0x4,%eax
 b83:	8b 04 85 84 13 00 00 	mov    0x1384(,%eax,4),%eax
 b8a:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b90:	05 90 13 00 00       	add    $0x1390,%eax
 b95:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 b9b:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 b9f:	a1 6c 13 00 00       	mov    0x136c,%eax
 ba4:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 baa:	05 90 14 00 00       	add    $0x1490,%eax
 baf:	8b 40 04             	mov    0x4(%eax),%eax
 bb2:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 bb5:	7f bc                	jg     b73 <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
 bb7:	c9                   	leave  
 bb8:	c3                   	ret    

00000bb9 <uthread_exit>:

void uthread_exit()
{
 bb9:	55                   	push   %ebp
 bba:	89 e5                	mov    %esp,%ebp
 bbc:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 bbf:	60                   	pusha  
	alarm(0);
 bc0:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 bc7:	e8 b4 f7 ff ff       	call   380 <alarm>
	asm("popa");
 bcc:	61                   	popa   
	ttable[c_thread].state = T_FREE;
 bcd:	a1 6c 13 00 00       	mov    0x136c,%eax
 bd2:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bd8:	05 90 13 00 00       	add    $0x1390,%eax
 bdd:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
 be3:	a1 6c 13 00 00       	mov    0x136c,%eax
 be8:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bee:	05 80 13 00 00       	add    $0x1380,%eax
 bf3:	8b 00                	mov    (%eax),%eax
 bf5:	85 c0                	test   %eax,%eax
 bf7:	74 1d                	je     c16 <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
 bf9:	a1 6c 13 00 00       	mov    0x136c,%eax
 bfe:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c04:	05 80 13 00 00       	add    $0x1380,%eax
 c09:	8b 40 0c             	mov    0xc(%eax),%eax
 c0c:	89 04 24             	mov    %eax,(%esp)
 c0f:	e8 10 fa ff ff       	call   624 <free>
 c14:	eb 05                	jmp    c1b <uthread_exit+0x62>
	else
		safe_exit();
 c16:	e8 fa fd ff ff       	call   a15 <safe_exit>
	uthread_awake();
 c1b:	e8 44 ff ff ff       	call   b64 <uthread_awake>
	uthread_switch();
 c20:	e8 38 fe ff ff       	call   a5d <uthread_switch>
	asm("popa");
 c25:	61                   	popa   
}
 c26:	c9                   	leave  
 c27:	c3                   	ret    

00000c28 <uthread_self>:

// task 2.6

int uthread_self()
{
 c28:	55                   	push   %ebp
 c29:	89 e5                	mov    %esp,%ebp
	return c_thread;
 c2b:	a1 6c 13 00 00       	mov    0x136c,%eax
}
 c30:	5d                   	pop    %ebp
 c31:	c3                   	ret    

00000c32 <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
 c32:	55                   	push   %ebp
 c33:	89 e5                	mov    %esp,%ebp
 c35:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 c38:	60                   	pusha  
	alarm(0);
 c39:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 c40:	e8 3b f7 ff ff       	call   380 <alarm>
	ttable[c_thread].state = T_SLEEPING;
 c45:	a1 6c 13 00 00       	mov    0x136c,%eax
 c4a:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c50:	05 90 13 00 00       	add    $0x1390,%eax
 c55:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
 c5b:	e8 fd fd ff ff       	call   a5d <uthread_switch>
	asm("popa");
 c60:	61                   	popa   
}
 c61:	c9                   	leave  
 c62:	c3                   	ret    

00000c63 <uthread_join>:

int uthread_join(int tid)
{
 c63:	55                   	push   %ebp
 c64:	89 e5                	mov    %esp,%ebp
 c66:	53                   	push   %ebx
 c67:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
 c6a:	60                   	pusha  
	ticks = getTicks();
 c6b:	e8 18 f7 ff ff       	call   388 <getTicks>
 c70:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 c73:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 c7a:	e8 01 f7 ff ff       	call   380 <alarm>
	asm("popa");
 c7f:	61                   	popa   
	if (ttable[tid].state != T_FREE)
 c80:	8b 45 08             	mov    0x8(%ebp),%eax
 c83:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c89:	05 90 13 00 00       	add    $0x1390,%eax
 c8e:	8b 00                	mov    (%eax),%eax
 c90:	85 c0                	test   %eax,%eax
 c92:	74 5e                	je     cf2 <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
 c94:	8b 45 08             	mov    0x8(%ebp),%eax
 c97:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c9d:	05 10 01 00 00       	add    $0x110,%eax
 ca2:	05 80 13 00 00       	add    $0x1380,%eax
 ca7:	8d 48 04             	lea    0x4(%eax),%ecx
 caa:	8b 45 08             	mov    0x8(%ebp),%eax
 cad:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 cb3:	05 90 14 00 00       	add    $0x1490,%eax
 cb8:	8b 40 04             	mov    0x4(%eax),%eax
 cbb:	8b 15 6c 13 00 00    	mov    0x136c,%edx
 cc1:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 cc7:	81 c2 80 13 00 00    	add    $0x1380,%edx
 ccd:	8b 12                	mov    (%edx),%edx
 ccf:	8b 5d 08             	mov    0x8(%ebp),%ebx
 cd2:	6b db 46             	imul   $0x46,%ebx,%ebx
 cd5:	01 c3                	add    %eax,%ebx
 cd7:	83 c3 04             	add    $0x4,%ebx
 cda:	89 14 9d 84 13 00 00 	mov    %edx,0x1384(,%ebx,4)
 ce1:	83 c0 01             	add    $0x1,%eax
 ce4:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
 ce6:	e8 47 ff ff ff       	call   c32 <uthread_sleep>
		return 0;
 ceb:	b8 00 00 00 00       	mov    $0x0,%eax
 cf0:	eb 12                	jmp    d04 <uthread_join+0xa1>
	}
	asm("pusha");
 cf2:	60                   	pusha  
	alarm(ticks);
 cf3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 cf6:	89 04 24             	mov    %eax,(%esp)
 cf9:	e8 82 f6 ff ff       	call   380 <alarm>
	asm("popa");
 cfe:	61                   	popa   
	return -1;
 cff:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 d04:	83 c4 24             	add    $0x24,%esp
 d07:	5b                   	pop    %ebx
 d08:	5d                   	pop    %ebp
 d09:	c3                   	ret    

00000d0a <queue_init>:

void queue_init(struct tqueue *q)
{
 d0a:	55                   	push   %ebp
 d0b:	89 e5                	mov    %esp,%ebp
	q->head = 0;
 d0d:	8b 45 08             	mov    0x8(%ebp),%eax
 d10:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
 d17:	00 00 00 
	q->tail = 0;
 d1a:	8b 45 08             	mov    0x8(%ebp),%eax
 d1d:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
 d24:	00 00 00 
}
 d27:	5d                   	pop    %ebp
 d28:	c3                   	ret    

00000d29 <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
 d29:	55                   	push   %ebp
 d2a:	89 e5                	mov    %esp,%ebp
 d2c:	57                   	push   %edi
 d2d:	56                   	push   %esi
 d2e:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
 d2f:	8b 45 08             	mov    0x8(%ebp),%eax
 d32:	8b 00                	mov    (%eax),%eax
 d34:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
 d3a:	8b 45 08             	mov    0x8(%ebp),%eax
 d3d:	8b 00                	mov    (%eax),%eax
 d3f:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
 d45:	39 c2                	cmp    %eax,%edx
 d47:	75 07                	jne    d50 <dequeue+0x27>
		return 0;
 d49:	b9 00 00 00 00       	mov    $0x0,%ecx
 d4e:	eb 31                	jmp    d81 <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
 d50:	8b 45 08             	mov    0x8(%ebp),%eax
 d53:	8b 18                	mov    (%eax),%ebx
 d55:	8b 45 08             	mov    0x8(%ebp),%eax
 d58:	8b 10                	mov    (%eax),%edx
 d5a:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
 d60:	89 c1                	mov    %eax,%ecx
 d62:	c1 f9 1f             	sar    $0x1f,%ecx
 d65:	c1 e9 1a             	shr    $0x1a,%ecx
 d68:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 d6b:	83 e6 3f             	and    $0x3f,%esi
 d6e:	89 f7                	mov    %esi,%edi
 d70:	29 cf                	sub    %ecx,%edi
 d72:	89 f9                	mov    %edi,%ecx
 d74:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
 d77:	83 c0 01             	add    $0x1,%eax
 d7a:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
 d80:	90                   	nop
 d81:	89 c8                	mov    %ecx,%eax
}
 d83:	5b                   	pop    %ebx
 d84:	5e                   	pop    %esi
 d85:	5f                   	pop    %edi
 d86:	5d                   	pop    %ebp
 d87:	c3                   	ret    

00000d88 <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
 d88:	55                   	push   %ebp
 d89:	89 e5                	mov    %esp,%ebp
 d8b:	57                   	push   %edi
 d8c:	56                   	push   %esi
 d8d:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
 d8e:	8b 45 08             	mov    0x8(%ebp),%eax
 d91:	8b 18                	mov    (%eax),%ebx
 d93:	8b 45 08             	mov    0x8(%ebp),%eax
 d96:	8b 10                	mov    (%eax),%edx
 d98:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
 d9e:	89 c1                	mov    %eax,%ecx
 da0:	c1 f9 1f             	sar    $0x1f,%ecx
 da3:	c1 e9 1a             	shr    $0x1a,%ecx
 da6:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 da9:	83 e6 3f             	and    $0x3f,%esi
 dac:	89 f7                	mov    %esi,%edi
 dae:	29 cf                	sub    %ecx,%edi
 db0:	89 f9                	mov    %edi,%ecx
 db2:	8b 35 6c 13 00 00    	mov    0x136c,%esi
 db8:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
 dbe:	81 c6 80 13 00 00    	add    $0x1380,%esi
 dc4:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
 dc7:	83 c0 01             	add    $0x1,%eax
 dca:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
 dd0:	5b                   	pop    %ebx
 dd1:	5e                   	pop    %esi
 dd2:	5f                   	pop    %edi
 dd3:	5d                   	pop    %ebp
 dd4:	c3                   	ret    

00000dd5 <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
 dd5:	55                   	push   %ebp
 dd6:	89 e5                	mov    %esp,%ebp
 dd8:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
 ddb:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
 de2:	e8 76 f9 ff ff       	call   75d <malloc>
 de7:	8b 55 08             	mov    0x8(%ebp),%edx
 dea:	89 02                	mov    %eax,(%edx)
	if (!value)
 dec:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 df0:	75 0c                	jne    dfe <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
 df2:	8b 45 08             	mov    0x8(%ebp),%eax
 df5:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
 dfc:	eb 0a                	jmp    e08 <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
 dfe:	8b 45 08             	mov    0x8(%ebp),%eax
 e01:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
 e08:	c9                   	leave  
 e09:	c3                   	ret    

00000e0a <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
 e0a:	55                   	push   %ebp
 e0b:	89 e5                	mov    %esp,%ebp
 e0d:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
 e10:	60                   	pusha  
	ticks = getTicks();
 e11:	e8 72 f5 ff ff       	call   388 <getTicks>
 e16:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 e19:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e20:	e8 5b f5 ff ff       	call   380 <alarm>
	asm("popa");
 e25:	61                   	popa   
	if (semaphore->state == S_LOCKED)
 e26:	8b 45 08             	mov    0x8(%ebp),%eax
 e29:	8b 40 04             	mov    0x4(%eax),%eax
 e2c:	83 f8 01             	cmp    $0x1,%eax
 e2f:	75 1c                	jne    e4d <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
 e31:	8b 45 08             	mov    0x8(%ebp),%eax
 e34:	89 04 24             	mov    %eax,(%esp)
 e37:	e8 4c ff ff ff       	call   d88 <enqueue>
		uthread_sleep();
 e3c:	e8 f1 fd ff ff       	call   c32 <uthread_sleep>
		alarm(0);
 e41:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e48:	e8 33 f5 ff ff       	call   380 <alarm>
	}
	semaphore->state = S_LOCKED;
 e4d:	8b 45 08             	mov    0x8(%ebp),%eax
 e50:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
 e57:	8b 45 f4             	mov    -0xc(%ebp),%eax
 e5a:	89 04 24             	mov    %eax,(%esp)
 e5d:	e8 1e f5 ff ff       	call   380 <alarm>

}
 e62:	c9                   	leave  
 e63:	c3                   	ret    

00000e64 <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
 e64:	55                   	push   %ebp
 e65:	89 e5                	mov    %esp,%ebp
 e67:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
 e6a:	60                   	pusha  
	ticks = getTicks();
 e6b:	e8 18 f5 ff ff       	call   388 <getTicks>
 e70:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 e73:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e7a:	e8 01 f5 ff ff       	call   380 <alarm>
	asm("popa");
 e7f:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
 e80:	8b 45 08             	mov    0x8(%ebp),%eax
 e83:	89 04 24             	mov    %eax,(%esp)
 e86:	e8 9e fe ff ff       	call   d29 <dequeue>
 e8b:	89 45 f0             	mov    %eax,-0x10(%ebp)
 e8e:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 e92:	75 19                	jne    ead <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
 e94:	8b 45 08             	mov    0x8(%ebp),%eax
 e97:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
 e9e:	60                   	pusha  
		alarm(ticks);
 e9f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 ea2:	89 04 24             	mov    %eax,(%esp)
 ea5:	e8 d6 f4 ff ff       	call   380 <alarm>
		asm("popa");
 eaa:	61                   	popa   
 eab:	eb 0f                	jmp    ebc <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
 ead:	8b 45 f0             	mov    -0x10(%ebp),%eax
 eb0:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
 eb7:	e8 77 fc ff ff       	call   b33 <uthread_yield>
	}
}
 ebc:	c9                   	leave  
 ebd:	c3                   	ret    
